package tree.easy;

import tree.TreeNode;

public class searchBST {
    TreeNode treeNode = null;

    public TreeNode searchBST(TreeNode root, int val) {
        dfs(root, val);
        return treeNode;
    }

    public void dfs(TreeNode root, int val) {
        if (root == null) {
            return;
        }
        if (val > root.val) {
            dfs(root.right, val);
        } else if (val < root.val) {
            dfs(root.left, val);
        } else {
            treeNode = root;
            return;
        }
    }
}
